<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"
	trimDirectiveWhitespaces="true"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<script type="text/javascript" src="${pageContext.request.contextPath}/apps_res/plugin/tinymce/jquery-3.2.1.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/apps_res/plugin/tinymce/tinymce.min.js" referrerpolicy="origin"></script>
		<script>
			$(document).ready(function() {
				function init(_language) {
					$('body').html('');
					$('body').append('<textarea class="mytextarea" name="mytextarea"></textarea>');
					tinymce.init({
						selector: ".mytextarea", // change this value according to your HTML
						plugins: ' print preview fullpage powerpaste searchreplace autolink directionality visualblocks visualchars image imagetools link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists wordcount imagetools textpattern help',
						language: _language, //zh_CN
						theme: "silver",
						//toolbar: "newsave formatselect | bold italic strikethrough forecolor backcolor permanentpen formatpainter | link image media pageembed | alignleft aligncenter alignright alignjustify  | numlist bullist outdent indent | removeformat | addcomment| imageupload ",
						/* paste_data_images: true,
						image_advtab: true,
						remove_linebreaks: false, */
						//不能把这个设置去掉，不然图片路径会出错
						relative_urls: false,
						//不允许拖动大小
						resize: false,
	    				statusbar:false, // 状态栏 myButton
	    				menu: {
							file: {
								title: 'File',
								items: 'newdocument | print | preview | newsave'
							},
							view: {
								title: 'language',
								items: 'language'
							}
						},
						automatic_uploads: true, //自动上传	
						font_formats: '맑은고딕=맑은고딕;새굴림=새굴림;돋움=돋움;돋움체=돋움체;바탕체=바탕체;바탕=바탕;굴림=굴림;휴먼엑스포=휴먼엑스포;微软雅黑=微软雅黑;楷体=楷体;宋体=宋体;仿宋=仿宋;黑体=黑体;幼圆=幼圆;Andale Mono=andale mono,times; Arial=arial,helvetica,sans-serif; Arial Black=arial black,avant garde; Book Antiqua=book antiqua,palatino; Comic Sans MS=comic sans ms,sans-serif; Courier New=courier new,courier; Georgia=georgia,palatino; Helvetica=helvetica; Impact=impact,chicago; Symbol=symbol; Tahoma=tahoma,arial,helvetica,sans-serif; Terminal=terminal,monaco; Times New Roman=times new roman,times; Trebuchet MS=trebuchet ms,geneva; Verdana=verdana,geneva; Webdings=webdings; Wingdings=wingdings,zapf dingbats',
						images_upload_url: '${pageContext.request.contextPath}/showUeditor.do?method=uploadImage', //上传图片地址
						toolbar1: "undo redo| styleselect | fontselect | fontsizeselect | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent",
						toolbar2: " preview | forecolor backcolor emoticons | table | link image",
						init_instance_callback: function (editor) {
							var id = getQueryString("id");
							console.log(editor)
							$.ajax({
								url : '${pageContext.request.contextPath}/showUeditor.do?method=getCaseContext&id='+id,
								type : "get",
								success: function(status) {
									var str = status.substr(16,(status.length));
									var text =str.substr(0,str.lastIndexOf('}'));
									var context = encodeURIComponent(text.substr(0,(text.lastIndexOf('"'))));
									editor.setContent(decodeURIComponent(context));
								}
							});
						}, // 初始化绑定数据
						setup: function(editor) {
							editor.ui.registry.addMenuItem('newsave', {
								icon: 'close',
								text: 'close',
						        cmd: 'close',
								onAction: function() {
									window.close();
								}
							});
							if(_language == 'zh_CN') {
								editor.ui.registry.addMenuItem('language', {
									icon: 'reload',
									text: '한국어',
									cmd: '한국어',
									onAction: function() {
										init('ko_KR');
									}
								});
							} else {
								editor.ui.registry.addMenuItem('language', {
									icon: 'reload',
									text: '中文',
									cmd: '中文',
									onAction: function() {
										init('zh_CN')
									}
								});
							}
						},
						images_upload_handler: function(blobInfo, success, failure) {
							var xhr, formData;
							xhr = new XMLHttpRequest();
							xhr.withCredentials = false;
							xhr.open('POST', '${pageContext.request.contextPath}/showUeditor.do?method=uploadImage');
							xhr.onload = function() {
								var json;

								if(xhr.status != 200) {
									failure('HTTP Error: ' + xhr.status);
									return;
								}

								json = JSON.parse(xhr.responseText);
								console.info(json);
								if(!json || typeof json.url!= 'string') {
									failure('Invalid JSON: ' + xhr.responseText);
									return;
								}
								success(json.url);
							};
							console.info(blobInfo.filename());
							formData = new FormData();
							formData.append('file', blobInfo.blob(), blobInfo.filename());
							if(blobInfo.blob().type.indexOf("image") > -1) { //确保文件 避免是.bat
								xhr.send(formData);
							}
						}
					});
				}
				init('zh_CN');
			});

			function getQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
				var r = window.location.search.substr(1).match(reg);
				if(r != null) return unescape(r[2]);
				return null;
			}
		</script>
	</head>
	<body>
	</body>
</html>